using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the Publication class.
	/// </summary>
    [Serializable]
	public partial class PublicationCollection : ActiveList<Publication, PublicationCollection>
	{	   
		public PublicationCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>PublicationCollection</returns>
		public PublicationCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Publication o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Publication table.
	/// </summary>
	[Serializable]
	public partial class Publication : ActiveRecord<Publication>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Publication()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Publication(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Publication(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Publication(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Publication", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPublicationId = new TableSchema.TableColumn(schema);
				colvarPublicationId.ColumnName = "PublicationId";
				colvarPublicationId.DataType = DbType.Guid;
				colvarPublicationId.MaxLength = 0;
				colvarPublicationId.AutoIncrement = false;
				colvarPublicationId.IsNullable = false;
				colvarPublicationId.IsPrimaryKey = true;
				colvarPublicationId.IsForeignKey = false;
				colvarPublicationId.IsReadOnly = false;
				colvarPublicationId.DefaultSetting = @"";
				colvarPublicationId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPublicationId);
				
				TableSchema.TableColumn colvarRevision = new TableSchema.TableColumn(schema);
				colvarRevision.ColumnName = "Revision";
				colvarRevision.DataType = DbType.Int32;
				colvarRevision.MaxLength = 0;
				colvarRevision.AutoIncrement = true;
				colvarRevision.IsNullable = false;
				colvarRevision.IsPrimaryKey = false;
				colvarRevision.IsForeignKey = false;
				colvarRevision.IsReadOnly = false;
				colvarRevision.DefaultSetting = @"";
				colvarRevision.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRevision);
				
				TableSchema.TableColumn colvarDateStartOfPublication = new TableSchema.TableColumn(schema);
				colvarDateStartOfPublication.ColumnName = "DateStartOfPublication";
				colvarDateStartOfPublication.DataType = DbType.DateTime;
				colvarDateStartOfPublication.MaxLength = 0;
				colvarDateStartOfPublication.AutoIncrement = false;
				colvarDateStartOfPublication.IsNullable = false;
				colvarDateStartOfPublication.IsPrimaryKey = false;
				colvarDateStartOfPublication.IsForeignKey = false;
				colvarDateStartOfPublication.IsReadOnly = false;
				colvarDateStartOfPublication.DefaultSetting = @"";
				colvarDateStartOfPublication.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateStartOfPublication);
				
				TableSchema.TableColumn colvarDateEndOfPublication = new TableSchema.TableColumn(schema);
				colvarDateEndOfPublication.ColumnName = "DateEndOfPublication";
				colvarDateEndOfPublication.DataType = DbType.DateTime;
				colvarDateEndOfPublication.MaxLength = 0;
				colvarDateEndOfPublication.AutoIncrement = false;
				colvarDateEndOfPublication.IsNullable = true;
				colvarDateEndOfPublication.IsPrimaryKey = false;
				colvarDateEndOfPublication.IsForeignKey = false;
				colvarDateEndOfPublication.IsReadOnly = false;
				colvarDateEndOfPublication.DefaultSetting = @"";
				colvarDateEndOfPublication.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateEndOfPublication);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Publication",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("PublicationId")]
		[Bindable(true)]
		public Guid PublicationId 
		{
			get { return GetColumnValue<Guid>(Columns.PublicationId); }
			set { SetColumnValue(Columns.PublicationId, value); }
		}
		  
		[XmlAttribute("Revision")]
		[Bindable(true)]
		public int Revision 
		{
			get { return GetColumnValue<int>(Columns.Revision); }
			set { SetColumnValue(Columns.Revision, value); }
		}
		  
		[XmlAttribute("DateStartOfPublication")]
		[Bindable(true)]
		public DateTime DateStartOfPublication 
		{
			get { return GetColumnValue<DateTime>(Columns.DateStartOfPublication); }
			set { SetColumnValue(Columns.DateStartOfPublication, value); }
		}
		  
		[XmlAttribute("DateEndOfPublication")]
		[Bindable(true)]
		public DateTime? DateEndOfPublication 
		{
			get { return GetColumnValue<DateTime?>(Columns.DateEndOfPublication); }
			set { SetColumnValue(Columns.DateEndOfPublication, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varPublicationId,DateTime varDateStartOfPublication,DateTime? varDateEndOfPublication,string varCreatedBy)
		{
			Publication item = new Publication();
			
			item.PublicationId = varPublicationId;
			
			item.DateStartOfPublication = varDateStartOfPublication;
			
			item.DateEndOfPublication = varDateEndOfPublication;
			
			item.CreatedBy = varCreatedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varPublicationId,int varRevision,DateTime varDateStartOfPublication,DateTime? varDateEndOfPublication,string varCreatedBy)
		{
			Publication item = new Publication();
			
				item.PublicationId = varPublicationId;
			
				item.Revision = varRevision;
			
				item.DateStartOfPublication = varDateStartOfPublication;
			
				item.DateEndOfPublication = varDateEndOfPublication;
			
				item.CreatedBy = varCreatedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn PublicationIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn RevisionColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn DateStartOfPublicationColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn DateEndOfPublicationColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PublicationId = @"PublicationId";
			 public static string Revision = @"Revision";
			 public static string DateStartOfPublication = @"DateStartOfPublication";
			 public static string DateEndOfPublication = @"DateEndOfPublication";
			 public static string CreatedBy = @"CreatedBy";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
